From 438289a1bd93df494bd56b1d9bc03d9cfc079225 Mon Sep 17 00:00:00 2001 From: "atse@norwich.uk.xensource.com" Date: Thu, 28 Sep 2006 11:50:51 +0100 Subject: [PATCH] [XM] Removed traceback printing for non ACMError exceptions Removing try,except block as cfgbootpolicy should allow exceptions to propagate instead of printing traceback to stdout. (http://bugzilla.xensource.com/bugzilla/show_bug.cgi?id=778) Changed usage of string.join, string.split when creating security policy path name. Signed-off-by: Alastair Tse --- tools/python/xen/xm/cfgbootpolicy.py | 73 +++++++++++++--------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/tools/python/xen/xm/cfgbootpolicy.py b/tools/python/xen/xm/cfgbootpolicy.py index d1ed910bf7..5cb8e83793 100644 --- a/tools/python/xen/xm/cfgbootpolicy.py +++ b/tools/python/xen/xm/cfgbootpolicy.py @@ -140,44 +140,41 @@ def insert_policy(boot_file, kernel_version, policy_name): def main(argv): - try: - user_kver = None - policy = None - if len(argv) == 2: - policy = argv[1] - elif len(argv) == 3: - policy = argv[1] - user_kver = argv[2] + user_kver = None + policy = None + if len(argv) == 2: + policy = argv[1] + elif len(argv) == 3: + policy = argv[1] + user_kver = argv[2] + else: + raise OptionError('Invalid number of arguments') + + if not policy_name_re.match(policy): + raise OptionError("Illegal policy name: '%s'" % policy) + + policy_file = '/'.join([policy_dir_prefix] + policy.split('.')) + src_binary_policy_file = policy_file + ".bin" + #check if .bin exists or if policy file exists + if not os.path.isfile(src_binary_policy_file): + if not os.path.isfile(policy_file + "-security_policy.xml"): + raise OptionError("Unknown policy '%s'" % policy) else: - raise OptionError('Invalid number of arguments') - - if not policy_name_re.match(policy): - err("Illegal policy name \'" + policy + "\'") - - policy_file = policy_dir_prefix + "/" + string.join(string.split(policy, "."), "/") - src_binary_policy_file = policy_file + ".bin" - #check if .bin exists or if policy file exists - if not os.path.isfile(src_binary_policy_file): - if not os.path.isfile(policy_file + "-security_policy.xml"): - err("Unknown policy \'" + policy +"\'") - else: - err("Cannot find binary file for policy \'" + policy + - "\'. Please use makepolicy to create binary file.") - dst_binary_policy_file = "/boot/" + policy + ".bin" - shutil.copyfile(src_binary_policy_file, dst_binary_policy_file) - - kernel_version = determine_kernelversion(user_kver) - insert_policy(boot_filename, kernel_version, policy) - print "Boot entry created and \'%s\' copied to /boot" % (policy + ".bin") - - except ACMError: - sys.exit(-1) - except: - traceback.print_exc(limit=1) - sys.exit(-1) - - + err_msg = "Cannot find binary file for policy '%s'." % policy + err_msg += " Please use makepolicy to create binary file." + raise OptionError(err_msg) + + dst_binary_policy_file = "/boot/" + policy + ".bin" + shutil.copyfile(src_binary_policy_file, dst_binary_policy_file) + + kernel_version = determine_kernelversion(user_kver) + insert_policy(boot_filename, kernel_version, policy) + print "Boot entry created and \'%s\' copied to /boot" % (policy + ".bin") if __name__ == '__main__': - main(sys.argv) - + try: + main(sys.argv) + except Exception, e: + sys.stderr.write('Error: ' + str(e) + '\n') + sys.exit(-1) + -- 2.30.2